/*
 * @Author: your name
 * @Date: 2021-05-27 17:34:16
 * @LastEditTime: 2021-05-28 10:21:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bazai_music_api\utils\callCloudFn.js
 */
const { getAccessToken } = require('../utils/getAccessToken.js')
const { default: axios } = require('axios')

const callCloudFn = async (ctx, fnName, params) => {
	const access_token = await getAccessToken()
	const url = `https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=${access_token}&env=${ctx.state.env}&name=${fnName}`
	try {
		const result = await axios.post(url, { ...params })
		return result
	} catch (err) {
		console.log('ACCESS_TOKEN,err', err)
	}
}

module.exports = callCloudFn
